﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DbConnect.Sql
{
    public static class SqlRequest
    {
        public const String Star = " * ";
        public const String Select = " Select ";
        public const String Where = " Where ";
        public const String From = " From ";
        public const String And = " And ";
        public const String Or = " Or ";
        public const String OrderBy = " Order By ";
        public const String Join = " Join ";
        public const String On = " On ";
        public const String LeftJoin = " Left Join ";
        public const String Equal = " = ";
        public const String Like = " Like ";
        public const String Percent = " %";
        public const String Delete = " Delete ";
        public const String Update = " Update ";
        public const String Set = " Set ";
        public const String Comma = ",";
        public const String Count = " Count";
        public const String LParenthesis = "(";
        public const String RParenthesis = ")";
        public const String Quote = "'";
        public const String InsertInto = "Insert into ";
        public const String Distinct = " Distinct ";
        public const String LastIDInserted = " last_insert_rowid() as ID ";

        public static String AddQuote(String value)
        {

            try
            {
                Logger.Log.TraceAction("SqlRequest.AddQuote", value);
                value = value.Replace("'", "''");
                value = "'" + value + "'";
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("SqlRequest.AddQuote", ex);

            }
            finally
            {

            }
            return value;
        }


    }

    public static class SqlWebsite
    {
        public const String TableName = " Website W";
        public const String Select = "Select * From Website Where ID=@ID";
        public const String InsertInto = "Insert into Website(wName, Url, Mainpage, Site_Type) Values(@wName, @Url,@Mainpage,@SiteType)";
        public const String Delete = "Delete from Website Where ID = @ID";
        public const String Update = "Update Website Set wName = @Name, Url = @Url, Mainpage=@Mainpage, Site_Type=@SiteType, Nb_Request = @NbRequest Where ID = @ID";
        public const String ID = " W.ID ";
        public const String Name = " W.wName ";
        public const String Url = " W.Url ";
        public const String Mainpage = " W.Mainpage ";
        public const String SiteType = " W.Site_Type ";
        public const String NbRequest = " W.Nb_Request ";
    }

    public static class SqlWRequest
    {
        public const String TableName = "Request R";
        public const String Select = "Select * From Request Where ID=@ID";
        public const String InsertInto = "Insert into Request(Website, rOrder, Req_Type, Resp_Type, Param) Values(@Website,@Order,@ReqType,@RespType,@Param)";
        public const String Update = "Update Request Set Website=@Website, rOrder=@Order, Req_Type=@ReqType, Resp_Type=@RespType, Param=@Param, Url=@Url Where ID=@ID";
        public const String Delete = "Delete from Request Where ID = @ID";
        public const String SelectByWebsite = "Select ID From Request Where Website = @Website";
        public const String ID = "R.ID ";
        public const String WebSite = "R.Website ";
        public const String Order = "R.rOrder ";
        public const String ReqType = "R.Req_Type ";
        public const String RespType = "R.Resp_Type ";
        public const String Param = "R.Param ";
    }

    public static class SqlSiteType
    {
        public const String TableName = " SiteType ST ";
        public const String InsertInto = " Insert Into SiteType(SiteTypeLib) Values(@Lib)";
        public const String Update = " Update SiteType Set SiteTypeLib = @Lib Where ID = @ID";
        public const String Delete = " Delete From SiteType Where ID = @ID";
        public const String ID = " ST.ID ";
        public const String Lib = " ST.SiteTypeLib ";
    }

    public static class SqlReqType
    {
        public const String TableName = "ReqType RT";
        public const String InsertInto = "Insert Into ReqType(ReqTypeLib) Values(@Lib)";
        public const String Update = "Update ReqType Set ReqTypeLib = @Lib Where ID = @ID";
        public const String Delete = "Delete From ReqType Where ID = @ID";
        public const String ID = "RT.ID ";
        public const String Lib = "RT.ReqTypeLib ";
    }

    public static class SqlSearch
    {
        public const String TableName = "Search S";
        public const String InsertInto = "Insert Into Search(SearchText, sCount) Values(@SearchTxt, @Count)";
        public const String Update = "Update Search Set sCount = (Count+1) Where ID = @ID";
        public const String Delete = "Delete From Search Where ID = @ID";
        public const String ID = "S.ID ";
        public const String SearchText = "S.SearchText ";
        public const String Count = "S.sCount ";

    }

    public static class SqlRespType
    {
        public const String TableName = "RespType RST";
        public const String InsertInto = "Insert Into RespType(RespTypeLib) Values(@Lib)";
        public const String Update = "Update RespType Set RespTypeLib = @Lib Where ID = @ID";
        public const String Delete = "Delete From RespType Where ID = @ID";
        public const String ID = "RST.ID ";
        public const String RespTypeLib = "RST.RespTypeLib ";
    }

    public static class SqlDownload
    {
        public const String TableName = "Download D";
        public const String InsertInto = "Insert Into Download(dName, Path, dDate, Status) Values(@Name, @Path, @Date, @Status)";
        public const String Update = "Update Download Set dName = @Name, Path=@Path, dDate=@Date, Status=@Status Where ID = @ID";
        public const String Delete = "Delete From Download Where ID = @ID";
        public const String Select = "Select * from Download Where ID = @ID";
        public const String ID = "D.ID ";
        public const String Name = "D.dName ";
        public const String Path = "D.Path ";
        public const String Date = "D.dDate ";
        public const String Status = "D.Status ";
    }

    public static class SqlStatus
    {
        public const String TableName = "Status STA";
        public const String Select = "Select * from Status where ID = @ID";
        public const String InsertInto = "Insert Into Status(StatusLib) Values(@Lib)";
        public const String Update = "Update Status Set StatusLib = @Lib Where ID = @ID";
        public const String Delete = "Delete From Status Where ID = @ID";
        public const String ID = "STA.ID ";
        public const String Lib = "STA.StatusLib ";

    }

    public static class SqlParameter
    {
        public const String TableName = "Parameter P";
        public const String InsertInto = "Insert Into Parameter(ParameterLib, ID_Req, ParameterDefaultValue) Values(@Lib, @Req, @DValue)";
        public const String Update = "Update Parameter Set ParameterLib = @Lib, ID_Req = @Req, ParameterDefaultValue = @DValue  Where ID = @ID";
        public const String Delete = "Delete From Parameter Where ID = @ID";
        public const String Select = "Select * From Parameter";
        public const String SelectByRequest = "Select ID From Parameter Where ID_Req = @Req";
        public const String ID = "P.ID ";
        public const String Lib = "P.ParameterLib ";
        public const String Req = "P.ID_Req ";
        public const String DValue = "P.ParameterDefaultValue ";

    }

    public static class ParamWebsite
    {
        public const String ID = "@ID";
        public const String Url = "@Url";
        public const String Mainpage = "@Mainpage";
        public const String SiteType = "@SiteType";
        public const String NbRequest = "@NbRequest";
        public const String Name = "@wName";
    }

    public static class ParamWRequest
    {
        public const String ID = "@ID";
        public const String WebSite = "@Website";
        public const String Order = "@rOrder";
        public const String ReqType = "@ReqType";
        public const String RespType = "@RespType";
        public const String Param = "@Param";
        public const String Url = "@Url";
    }

    public static class ParamSiteType
    {
        public const String ID = "@ID";
        public const String Lib = "@Lib";
    }

    public static class ParamReqType
    {
        public const String ID = "@ID";
        public const String Lib = "@Lib";
    }

    public static class ParamSearch
    {
        public const String ID = "@ID";
        public const String SearchText = "@SearchText";
        public const String Count = "@sCount";
    }

    public static class ParamRespType
    {
        public const String ID = "@ID";
        public const String Lib = "@Lib";
    }

    public static class ParamDownload
    {
        public const String ID = "@ID";
        public const String Name = "@dName";
        public const String Path = "@Path";
        public const String Date = "@dDate";
        public const String Status = "@Status";
    }

    public static class ParamStatus
    {
        public const String ID = "@ID";
        public const String Lib = "@Lib";
    }

    public static class ParamParameter
    {
        public const String ID = "@ID";
        public const String Lib = "@Lib";
        public const String Req = "@Req";
        public const String DefaultValue = "@DValue";
    }
}
